package org.xbill.DNS;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class RRset
  implements Serializable
{
  private static final long serialVersionUID = -597773583L;
  private short nsigs;
  private short position;
  private List rrs;

  public RRset()
  {
    this.rrs = new ArrayList(1);
    this.nsigs = 0;
    this.position = 0;
  }

  public RRset(RRset paramRRset)
  {
    monitorenter;
    try
    {
      this.rrs = ((List)((ArrayList)paramRRset.rrs).clone());
      this.nsigs = paramRRset.nsigs;
      this.position = paramRRset.position;
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public RRset(Record paramRecord)
  {
    safeAddRR(paramRecord);
  }

  /**
   * @deprecated
   */
  private Iterator iterator(boolean paramBoolean1, boolean paramBoolean2)
  {
    int i;
    int k;
    ArrayList localArrayList;
    monitorenter;
    try
    {
      int j;
      Iterator localIterator1;
      i = this.rrs.size();
      if (paramBoolean1)
      {
        j = i - this.nsigs;
        if (j != 0)
          break label205;
        Iterator localIterator2 = Collections.EMPTY_LIST.iterator();
        localIterator1 = localIterator2;
      }
      while (true)
      {
        while (true)
        {
          monitorexit;
          return localIterator1;
          j = this.nsigs;
        }
        localArrayList = new ArrayList(j);
        if (!(paramBoolean1))
          break label176;
        localArrayList.addAll(this.rrs.subList(k, j));
        if (k != 0)
          localArrayList.addAll(this.rrs.subList(0, k));
        localIterator1 = localArrayList.iterator();
      }
      label176: label205: if (this.position >= j)
        this.position = 0;
    }
    finally
    {
      while (true)
      {
        do
          do
          {
            monitorexit;
            throw localObject;
          }
          while (!(paramBoolean1));
        while (paramBoolean2);
        k = 0;
      }
    }
  }

  private String iteratorToString(Iterator paramIterator)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    while (true)
    {
      do
      {
        if (!(paramIterator.hasNext()))
          return localStringBuffer.toString();
        Record localRecord = (Record)paramIterator.next();
        localStringBuffer.append("[");
        localStringBuffer.append(localRecord.rdataToString());
        localStringBuffer.append("]");
      }
      while (!(paramIterator.hasNext()));
      localStringBuffer.append(" ");
    }
  }

  private void safeAddRR(Record paramRecord)
  {
    if (!(paramRecord instanceof RRSIGRecord))
      if (this.nsigs == 0)
        this.rrs.add(paramRecord);
    while (true)
    {
      while (true)
      {
        return;
        this.rrs.add(this.rrs.size() - this.nsigs, paramRecord);
      }
      this.rrs.add(paramRecord);
      this.nsigs = (1 + this.nsigs);
    }
  }

  /**
   * @deprecated
   */
  public void addRR(Record paramRecord)
  {
    Record localRecord1;
    monitorenter;
    try
    {
      throw new IllegalArgumentException("record does not match rrset");
    }
    finally
    {
      while (true)
      {
        do
        {
          monitorexit;
          throw localObject;
          if (paramRecord.getTTL() != localRecord1.getTTL())
          {
            if (paramRecord.getTTL() <= localRecord1.getTTL())
              break label170;
            paramRecord = paramRecord.cloneRecord();
            paramRecord.setTTL(localRecord1.getTTL());
          }
        }
        while (this.rrs.contains(paramRecord));
        safeAddRR(paramRecord);
      }
      while (true)
      {
        while (true)
        {
          if (i >= this.rrs.size());
          Record localRecord2 = ((Record)this.rrs.get(i)).cloneRecord();
          localRecord2.setTTL(paramRecord.getTTL());
          this.rrs.set(i, localRecord2);
          ++i;
        }
        label170: int i = 0;
      }
    }
  }

  /**
   * @deprecated
   */
  public void clear()
  {
    monitorenter;
    try
    {
      this.rrs.clear();
      this.position = 0;
      this.nsigs = 0;
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  /**
   * @deprecated
   */
  public void deleteRR(Record paramRecord)
  {
    monitorenter;
    try
    {
      if ((this.rrs.remove(paramRecord)) && (paramRecord instanceof RRSIGRecord))
        this.nsigs -= 1;
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  /**
   * @deprecated
   */
  public Record first()
  {
    monitorenter;
    try
    {
      throw new IllegalStateException("rrset is empty");
    }
    finally
    {
      monitorexit;
      throw localObject;
      Record localRecord = (Record)this.rrs.get(0);
      monitorexit;
      return localRecord;
    }
  }

  public int getDClass()
  {
    return first().getDClass();
  }

  public Name getName()
  {
    return first().getName();
  }

  /**
   * @deprecated
   */
  public long getTTL()
  {
    monitorenter;
    try
    {
      long l = first().getTTL();
      monitorexit;
      return l;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public int getType()
  {
    return first().getRRsetType();
  }

  /**
   * @deprecated
   */
  public Iterator rrs()
  {
    monitorenter;
    try
    {
      Iterator localIterator = iterator(true, true);
      monitorexit;
      return localIterator;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  /**
   * @deprecated
   */
  public Iterator rrs(boolean paramBoolean)
  {
    monitorenter;
    try
    {
      Iterator localIterator = iterator(true, paramBoolean);
      monitorexit;
      return localIterator;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  /**
   * @deprecated
   */
  public Iterator sigs()
  {
    monitorenter;
    try
    {
      Iterator localIterator = iterator(false, false);
      monitorexit;
      return localIterator;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  /**
   * @deprecated
   */
  public int size()
  {
    monitorenter;
    try
    {
      int i = this.rrs.size();
      int j = this.nsigs;
      int k = i - j;
      monitorexit;
      return k;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public String toString()
  {
    String str;
    if (this.rrs == null)
      str = "{empty}";
    while (true)
    {
      return str;
      StringBuffer localStringBuffer = new StringBuffer();
      localStringBuffer.append("{ ");
      localStringBuffer.append(getName() + " ");
      localStringBuffer.append(getTTL() + " ");
      localStringBuffer.append(DClass.string(getDClass()) + " ");
      localStringBuffer.append(Type.string(getType()) + " ");
      localStringBuffer.append(iteratorToString(iterator(true, false)));
      if (this.nsigs > 0)
      {
        localStringBuffer.append(" sigs: ");
        localStringBuffer.append(iteratorToString(iterator(false, false)));
      }
      localStringBuffer.append(" }");
      str = localStringBuffer.toString();
    }
  }
}